﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using BCDto.CRM.IndustryCategory;
using BCTMSRESTful.Configs;
using BCService.Utils;
using BCService.CRM.IndustryCategory;

namespace BCTMSRESTful.Controllers.Management.CRM.IndustryCategory
{
    /// <summary>
    /// 行业类别
    /// </summary>
    [ApiExplorerSettings(GroupName = "CRMAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class IndustryCategoryController : ManagementBaseController
    {
        private readonly IIndustryCategoryService industryCategoryService;

        public IndustryCategoryController(IIndustryCategoryService industryCategoryService)
        {
            this.industryCategoryService = industryCategoryService;
        }

        #region 添加行业类别
        /// <summary>
        ///  添加行业类别
        /// </summary>
        /// <param name="requestDto">行业类别信息</param>
        /// <response code="201">添加行业类别成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加行业类别")]
        [ProducesResponseType(typeof(IndustryCategoryDto), 201)]
        public IActionResult Post(
            [FromBody]IndustryCategoryRequestDto requestDto)
        {
            var result = this.industryCategoryService.Add(requestDto);
            return StatusCode((int)HttpStatusCode.Created, result);
        }
        #endregion

        #region 修改行业类别
        /// <summary>
        ///  修改行业类别
        /// </summary>
        /// <param name="industryCategoryId">行业类别Id</param>
        /// <param name="requestDto">行业类别信息</param>
        /// <response code="200">修改行业类别成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{industry_category_id}")]
        [Log("修改行业类别")]
        [ProducesResponseType(typeof(IndustryCategoryDto), 200)]
        public IActionResult Put([FromRoute(Name = "industry_category_id")]long industryCategoryId, [FromBody]IndustryCategoryRequestDto requestDto)
        {
            IndustryCategoryPutDto putDto = requestDto.As<IndustryCategoryPutDto>();
            putDto.IndustryCategoryId = industryCategoryId;
            return StatusCode((int)HttpStatusCode.OK, this.industryCategoryService.Update(putDto));
        }
        #endregion

        #region 删除行业类别
        /// <summary>
        ///  删除行业类别
        /// </summary>
        /// <param name="industryCategoryId">行业类别Id</param>
        /// <response code="204">删除行业类别成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{industry_category_id}")]
        [Log("删除行业类别")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "industry_category_id")]long industryCategoryId)
        {
            this.industryCategoryService.Delete(industryCategoryId);
            return StatusCode((int)HttpStatusCode.NoContent);
        }
        #endregion

        #region 获取行业类别
        /// <summary>
        ///  获取行业类别
        /// </summary>
        /// <param name="industryCategoryId">行业类别Id</param>
        /// <response code="200">获取行业类别</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{industry_category_id}")]
        [ProducesResponseType(typeof(IndustryCategoryDto), 200)]
        public IActionResult Get([FromRoute(Name = "industry_category_id")]long industryCategoryId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.industryCategoryService.Get(industryCategoryId));
        }
        #endregion

        #region 获取行业类别列表
        /// <summary>
        ///  获取行业类别列表
        /// </summary>
        /// <response code="200">获取行业类别列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(IEnumerable<IndustryCategoryDto>), 200)]
        public IActionResult GetList()
        {
            return StatusCode((int)HttpStatusCode.OK, this.industryCategoryService.GetList());
        }
        #endregion

        #region 获取行业类别（分页）
        /// <summary>
        ///  获取行业类别（分页）
        /// </summary>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取行业类别（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<IndustryCategoryDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "sort_name")]string sortName,
            [FromQuery(Name = "ascending")]bool? ascending,
            [FromQuery(Name = "index")]int index = 1,
            [FromQuery(Name = "size")]int size = 10)
        {
            return StatusCode((int)HttpStatusCode.OK, this.industryCategoryService.Query(start, end, sortName, ascending, index, size));
        }
        #endregion
    }
}

